import unittest,requests

class A3amll(unittest.TestCase):

    token=None
    spid = None

    def test_a_A3mall_login(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        json = {"username": "13057972962", "password": "123456"}
        login1 = requests.post(url=url, json=json)
        print(login1.json())
        A3amll.token = login1.json()['data']['token']
        print(A3amll.token)

    def test_b_A3mall_info(self):
        url = 'http://10.59.9.14:7003/api/ucenter/info'
        headers = {"Auth-Token":f"Bearer {A3amll.token}"}
        info = requests.get(url=url,headers=headers)
        print(info.json())

    def test_c_A3mall_point(self):
        url = 'http://10.59.9.14:7003/api/point?page=1&type=0&sort=1'
        point = requests.get(url=url)
        print(point.json())
        A3amll.spid=point.json()['data']['list'][0]['id']
        print(A3amll.spid)

    def test_d_A3mall_view(self):
        url = 'http://10.59.9.14:7003/api/point/view?id='+ str(A3amll.spid)
        view = requests.get(url=url)
        print(view.json())

    def test_e_A3mall_confirm(self):
        url = 'http://10.59.9.14:7003/api/order/confirm?id='+str(A3amll.spid)+'&type=point&sku_id=&num=1&shipping_type=1'
        headers = {"Auth-Token": f"Bearer {A3amll.token}"}
        confirm = requests.get(url=url,headers=headers)
        print(confirm.json())

    def test_f_A3mall_address(self):
        url = 'http://10.59.9.14:7003/api/order/confirm?id='+str(A3amll.spid)+'&type=point&sku_id=&num=1&shipping_type=1&address_id=182'
        headers = {"Auth-Token": f"Bearer {A3amll.token}"}
        address = requests.get(url=url,headers=headers)
        print(address.json())

    order_id = None

    def test_g_A3mall_create(self):
        url = 'http://10.59.9.14:7003/api/order/create'
        headers = {"Auth-Token": f"Bearer {A3amll.token}"}
        json = {"id":A3amll.spid,"type":"point","address_id":182,"store_id":"0","shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.14:7003/wap/pages/cart/confirm?id=13&sku_id=&num=1&type=point","sku_id":"","num":"1"}
        create = requests.post(url=url,headers=headers,json=json)
        print(create.json())
        A3amll.order_id=create.json()['data']['order_id']
        print(A3amll.order_id)

    def test_h_A3mall_detail(self):
        url = 'http://10.59.9.14:7003/api/order/detail'
        headers = {"Auth-Token": "Bearer " + A3amll.token}
        json ={"id":A3amll.order_id}
        detail = requests.post(url=url,headers=headers,json=json)
        print(detail.json())


if __name__ == '__main__':
    unittest.main()
